package Test.PracticeBrokingQueue;

import java.util.concurrent.TimeUnit;

/**
 * @author handsomePot
 * @date 2021/12/28 23:11
 */
public class TestMiniQueue {

    public static void main(String[] args) {

        BrokingQueue<Integer> queue = new MiniArrayBrokingQueue(10);

        Thread producer = new Thread(() -> {
            int i = 0;
            while (true) {
                i++;
                if (i == 10) {
                    i = 0;
                }
                System.out.println("生产数据：" + i);
                queue.put(i);
                try {
                    TimeUnit.MILLISECONDS.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        producer.start();


        Thread consumer = new Thread(() -> {
            while (true) {
                Integer take = queue.take();
                System.out.println("消费者 消费数据：" + take);
                try {
                    TimeUnit.MILLISECONDS.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        consumer.start();

    }

}
